﻿<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.10.3.custom.min.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />						<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.10.2.min.js"></script>		<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->
<script src="js/jquery.cookie.js"></script>																	<!-- 操作cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script>												<!-- 本專案自行定義 JS -->

<title>維護子系統</title>

<script type="text/javascript">

function checkDuplicated() {
	var sysId = $("#subsysId").val();
	var ll = $("#grid1").jqGrid('getDataIDs');
	var isDuplicated = false;
	for(var i=0;i<ll.length;i++){
		if (ll[i] == sysId ) {
			isDuplicated = true;
		}
	}
	
	if (isDuplicated) {
		alert(sysId+"已經存在，子系統ID不可重覆 !");
	} else {
		var sysName = $("#subSysName").val();
		var dataAdd = {"subsysId":sysId,"subSysName":sysName};
		var _iCount = $("#grid1").jqGrid('getGridParam', 'records');
		$("#grid1").jqGrid('addRowData', _iCount+1,dataAdd);
		$("form#kk input#subsysId").val(sysId);
	} 
	return [];
}



$(document).ready(function() {
	
	if ($.cookie("userId") == null) {
		alert("請先登入系統");
		location.assign("index.html");
	} else {
		initPage("維護子系統");
	}
	
	$("#grid1").jqGrid({
		url:'QuerySubSys',
		datatype: "json",
		type: "post",
	   	colNames:['子系統ID', '子系統名稱'],
	   	colModel:[
	   		{name:'subsysId',index:'subsysId',key:true,editable:true,editrules:{required:true}},
	   		{name:'subSysName',index:'subSysName',editable:true,editrules:{required:true}}
	   	],
	   	rowNum: 6,
	   	forceFit: true,
	   	pager: '#pager',
	   	rownumbers: true,
	   	viewrecords: true,	
	    caption:"設定子系統"
	}).navGrid('#pager',{edit:true,add:true,del:true,search:false,refresh:false}
	,{	// edit
		url: "ManipulateGridSubSys",
		mtype: "POST",
		editData: {
			bssId: function() { return "MBMS"; },
			dbType: function() { return $.cookie("dbType"); },
			currentUser: function() { return $.cookie("userId"); }
		},
		onclickSubmit:function() {
			var sysId = $("#subsysId").val();
			var sysName = $("#subSysName").val();
			var dataAdd = {"subsysId":sysId,"subSysName":sysName};
			$("#grid1").jqGrid('setRowData', sysId,dataAdd);
		}
	}
	,{	// add
		url: "ManipulateGridSubSys",
		mtype: "POST",
		editData: {
			bssId: function() { return "MBMS"; },
			dbType: function() { return $.cookie("dbType"); },
			currentUser: function() { return $.cookie("userId"); }
		},
		onclickSubmit:function() {
			checkDuplicated();
		}
	},{	// Delete
		url: "ManipulateGridSubSys",
		mtype: "POST",
		delData: {
			bssId: function() { return "MBMS"; },
			dbType: function() { return $.cookie("dbType"); },
			currentUser: function() { return $.cookie("userId"); }
		}
	}
);
	
}).tooltip();
</script>

</head>
<body>

<div id="header"></div>
<p>


	<table id="grid1"></table>
	<div id="pager"></div>
	<form id="kk">
		<input id="subsysId" type="hidden"> <input id="subSysName"
			type="hidden">
	</form>
</body>
</html>